/**
 * Created by cuppi on 2016/12/2.
 */

import NumberTool from './NumberTool.js';

class UnitTool {
  static distanceStringFromKm(distance) {
    if (distance < 0) {
      return '0m';
    }
    if (distance < 1) {
      return distance * 1000 + 'm';
    }
    return distance + 'km';
  }

  static formatPrice(price) {
    return NumberTool.fixNumberTo(price, 2);
  }

  static formatArea(area) {
    if (!area) {
      return;
    }
    area = area.replace(/上映/, '');
    area = area.replace(/中国大陆/, '中国');
    return area.replace(/大陆/, '中国');
  }

  static formatActors(actors) {
    if (!actors) {
      return;
    }
    // var decToHex = function(str) {
    //   var res = [];
    //   for (let i = 0; i < str.length; i++) {
    //     res[i] = ('00' + str.charCodeAt(i).toString(16)).slice(-4);
    //   }
    //   return '\\u' + res.join('\\u');
    // }
    // console.log(decToHex(category));
    let sepedArray = actors.replace(/\|/g, ',').replace(/\s/g, '').replace(/\u002c/g, ',').split(',');
    sepedArray = sepedArray.filter(string => {
      if (string.length <= 1) {
        return false;
      }
      return true;
    });
    return sepedArray.join(' , ');
  }

  static formatCategory(category) {
    if (!category) {
      return;
    }
    // var decToHex = function(str) {
    //   var res = [];
    //   for (let i = 0; i < str.length; i++) {
    //     res[i] = ('00' + str.charCodeAt(i).toString(16)).slice(-4);
    //   }
    //   return '\\u' + res.join('\\u');
    // }
    // console.log(decToHex(category));
    let sepedArray = category.replace(/\|/g, ',').replace(/\s/g, '').replace(/\u002c/g, ',').split(',');
    sepedArray = sepedArray.filter(string => {
      if (string.length <= 1) {
        return false;
      }
      return true;
    });
    return sepedArray.join(' , ');
  }

  static formatDimensional(dimensional) {
    if (!dimensional) {
      return;
    }
    // var decToHex = function(str) {
    //   var res = [];
    //   for (let i = 0; i < str.length; i++) {
    //     res[i] = ('00' + str.charCodeAt(i).toString(16)).slice(-4);
    //   }
    //   return '\\u' + res.join('\\u');
    // }
    // console.log(decToHex(category));
    let sepedArray = dimensional.replace(/\|/g, ',').replace(/\s/g, '').replace(/\u002c/g, ',').split(',');
    sepedArray = sepedArray.filter(string => {
      if (string.length <= 1) {
        return false;
      }
      return true;
    });
    return sepedArray.join(' , ');
  }

}

export default UnitTool;
